// import { useRouter } from "vue-router";
import axios from "axios"

const service = axios.create()

service.interceptors.request.use(
    (config) => {
        // 给请求头添加token
        // const token = localStorage.getItem('user_token')
        // if (token) {
        //     config.headers['x-token'] = token;
        // }
        return config
    },
    error => {
        window.console.log(error) // for debug
        Promise.reject(error)
    }
)

// response 拦截器,数据返回后进行一些处理
service.interceptors.response.use(
    (response) => {
        const res = response
        if (res.data.code == 200) {
            return res;
        } else {
            Promise.reject(res.data.msg);
        }
    },
    (err) => {
        // DO something
        return Promise.reject(err.response.data);
    }
)
export default service